﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

// MonoBehaviour 상속받아 오브젝트 관리
public class ObjectBase : MonoBehaviour {

    public static float rayCastDistance = 100.0f;
    //public bool isAbleRaycast = true;
    Dictionary<string, Component> FindedComponentDic = new Dictionary<string, Component>();

    //void Update()
    //{
    //    if (isAbleRaycast)
    //        UpdateProcess();
    //}

    // Update is called once per frame
    public virtual void UpdateProcess()
    {

    }

    // position wrapper
    public void SetPos(Vector3 pos)
    {
        transform.localPosition = pos;
    }

    public void SetPosX(float X)
    {
        Vector3 t_Pos = transform.localPosition;
        t_Pos.x = X;
        transform.localPosition = t_Pos;
    }

    public void SetPosY(float Y)
    {
        Vector3 t_Pos = transform.localPosition;
        t_Pos.y = Y;
        transform.localPosition = t_Pos;
    }


    public void SetPosZ(float Z)
    {
        Vector3 t_Pos = transform.localPosition;
        t_Pos.z = Z;
        transform.localPosition = t_Pos;
    }

    // 찾은 component 재사용 로직
    public Component GetComp(string findType)
    {
        if (!FindedComponentDic.ContainsKey(findType))
            FindedComponentDic.Add(findType, gameObject.GetComponent(findType) as Component);

        return FindedComponentDic[findType] as Component;       
    }

    public Component AddComp(string addType)
    {
        if (!FindedComponentDic.ContainsKey(addType))
            FindedComponentDic.Add(addType, gameObject.AddComponent(addType) as Component);

        return FindedComponentDic[addType] as Component;
    }

    public void DelComp(string delType)
    {
        if (FindedComponentDic.ContainsKey(delType))
        {            
            Destroy(FindedComponentDic[delType]);
            FindedComponentDic.Remove(delType);           
        }
    }

    public bool Raycast(Ray ray, out RaycastHit hits)
    {
        //if (isAbleRaycast)
            return Physics.Raycast(ray, out hits, rayCastDistance);
        //else
        //{
        //    hits = new RaycastHit();
        //    return false;
        //}
    }
}
